from django.contrib import admin
admin.autodiscover()
from ims.sti.models import *


class SourceOptions(admin.ModelAdmin):
	list_display = ('name', 'description')
	search_fields = ('name', 'description')
	ordering = ('name',)

admin.site.register(Source, SourceOptions)
 





class KnowsInline(admin.TabularInline):
	model = Knows
	extra = 1


class TopicAssocOptions(admin.ModelAdmin):
	list_display = ('from_topic', 'to_topic', 'source', 'assoc_type')
	list_filter = ('source', 'assoc_type')

#admin.site.register(TopicAssoc, TopicAssocOptions)


class TopicAssocFromInline(admin.TabularInline):
	model = TopicAssoc
	fk_name = "from_topic"
	extra = 1


class TopicAssocToInline(admin.TabularInline):
	model = TopicAssoc
	fk_name = "to_topic"
	extra = 1

class TopicAuxInline(admin.TabularInline):
	model = TopicAux
	extra = 1


class TopicOptions(admin.ModelAdmin):
	list_display = ('name',)
	search_fields = ('name',)
	ordering = ('name',)
	inlines = (KnowsInline, TopicAuxInline, TopicAssocFromInline, TopicAssocToInline)

admin.site.register(Topic, TopicOptions)


class PersonOptions(admin.ModelAdmin):
	list_display = ('last_name', 'first_name', 'source',)
	list_filter = ('source',)
	search_fields = ('last_name', 'first_name')
	ordering = ('last_name', 'first_name', 'source',)
	inlines = (KnowsInline,)

admin.site.register(Person, PersonOptions)






class UsesInline(admin.TabularInline):
	model = Uses
	extra = 1


class LectureInline(admin.TabularInline):
	model = Lecture
	raw_id_fields = ("topics",)
	extra = 1

class LectureInline2(admin.TabularInline):
	model = Lecture
	extra = 1
	
	
class CourseOptions(admin.ModelAdmin):
	list_display = ('semester','name', 'description',)
	search_fields = ('semester','name', 'description')
	ordering = ('-semester','name',)
	inlines = (UsesInline,LectureInline2)

admin.site.register(Course, CourseOptions)



class EntryInline(admin.TabularInline):
	model = Entry
	extra = 1

class AliasOptions(admin.ModelAdmin):
	list_display = ("alias","entry")
	search_fields = ("alias__name","entry__name")
	ordering = ('entry','alias')

admin.site.register(Alias,AliasOptions)



class AliasInline(admin.TabularInline):
	model = Alias
	extra = 1
	
class EntryAuxInline(admin.TabularInline):
	model = EntryAux
	extra = 1
	
class EntryOptions(admin.ModelAdmin):
	list_display = ('name',)
	search_fields = ('name',)
	ordering = ('name',)
	inlines = (EntryAuxInline,AliasInline,)

admin.site.register(Entry,EntryOptions)
	

class PublisherOptions(admin.ModelAdmin):
	list_display = ('name','address','city','state_province','country','website',)
	search_fields = ('name','address','city','state_province','country',)
	ordering = ('name',)

admin.site.register(Publisher,PublisherOptions)


class AuthorOptions(admin.ModelAdmin):
	list_display = ('last_name','first_name')
	search_fields = ('last_name','first_name')
	ordering = ('last_name','first_name')

admin.site.register(Author,AuthorOptions)

	
class TOCInline(admin.TabularInline):
	model = TOC
	extra = 5


class BookOptions(admin.ModelAdmin):
	list_display = ('title','edition','ISBN','year','publisher','icon_url','url')
	search_fields = ('title','edition','ISBN','year','url')
	ordering = ('title','edition','year')
	list_filter = ('publisher',)
	# inlines = (TOCInline,)	# it takes too long to load all the entries

admin.site.register(Book,BookOptions)

class CoversInline(admin.TabularInline):
	model = Covers
	extra = 1

class LectureOptions(admin.ModelAdmin):
	list_display = ('course','number','source')
	search_fields = ('course__name','course__semester','course__description',)
	list_filter = ('course','number')
	ordering = ('course','number')
	inlines = (CoversInline,)

admin.site.register(Lecture,LectureOptions)

class CoversOptions(admin.ModelAdmin):
	list_display = ('lecture','topic','position',)
	search_fields = ('lecture__number','topic__name',)
	list_filter = ('lecture',)
	ordering = ('-lecture','position',)

admin.site.register(Covers,CoversOptions)

class TOCOptions(admin.ModelAdmin):
	list_display = ('position','book','topic','page')
	search_fields = ('position','book__title','topic__name','page')
	list_filter = ('book',)
	ordering = ('position','book',)

admin.site.register(TOC,TOCOptions)


	